package com.taiji.dianthus.controller;

import com.taiji.dianthus.common.BusinessMessage;
import com.taiji.dianthus.service.sys.OrgService;
import com.taiji.dianthus.service.sys.RoleUserService;
import com.taiji.dianthus.service.sys.UserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 支撑同步信息
 */
@Controller
@RequestMapping("/syn/info")
public class SynBaseInfoController {
    Log log = LogFactory.getLog(SynBaseInfoController.class);

    @Value("${user_role}")
    private String originUserRole;//普通用户

    @Autowired
    private UserService userService;
    @Autowired
    private RoleUserService roleUserService;
    @Autowired
    private OrgService orgService;

    /**
     * 新增用户
     *
     * @param jsonArrayStr
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/addUser")
    @ResponseBody
    public List<BusinessMessage> addUser(@RequestBody String jsonArrayStr) {
        return userService.addSynBaseUser(jsonArrayStr);
    }

    /**
     * 更新用户
     *
     * @param jsonArrayStr
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/updateUser")
    @ResponseBody
    public List<BusinessMessage> updateUser(@RequestBody String jsonArrayStr) {
        return userService.updateSynBaseUser(jsonArrayStr);

    }


    /**
     * 删除用户
     *
     * @param jsonArrayStr
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/deleteUser")
    @ResponseBody
    public List<BusinessMessage> deleteUser(@RequestBody String jsonArrayStr) {
        return userService.deleteSynBaseUser(jsonArrayStr);
    }

    /**
     * 新增组织
     *
     * @param jsonArrayStr
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/addOrg")
    @ResponseBody
    public List<BusinessMessage> addOrg(@RequestBody String jsonArrayStr) {
        return orgService.addSynBaseOrg(jsonArrayStr);
    }

    /**
     * 编辑组织
     *
     * @param jsonArrayStr
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/updateOrg")
    @ResponseBody
    public List<BusinessMessage> updateOrg(@RequestBody String jsonArrayStr) {
        return orgService.updateSynBaseOrg(jsonArrayStr);
    }


    /**
     * 删除组织
     *
     * @param
     * @return
     * @throws UnsupportedEncodingException
     */
    @RequestMapping(value = "/deleteOrg")
    @ResponseBody
    public List<BusinessMessage> deleteOry(@RequestBody String jsonArrayStr) {
      return orgService.deleteSynBaseOrg(jsonArrayStr);
    }


}
